/*
 * @Author: fengshan0525 2735332396@qq.com
 * @Date: 2023-03-17 20:42:43
 * @LastEditors: fengshan@0525 3183359488@qq.com
 * @LastEditTime: 2023-07-26 15:13:32
 * @FilePath: \nest-template\src\menu\menu.controller.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { AdminMenu } from '@libs/db/models/menu.model';
import {
  Controller,
  Post,
  Get,
  Body,
  Req,
  Delete,
  Param,
  UseGuards,
} from '@nestjs/common';
import { MenuService } from './menu.service';
import { ApiTags } from '@nestjs/swagger';
import { RoleGuard } from 'src/guards/role.guard';
import { Roles } from 'src/decorations/role.decorator';

@ApiTags('菜单')
@Controller('menu')
@UseGuards(RoleGuard)
export class MenuController {
  constructor(private readonly menuService: MenuService) {}

  @Post('getMenus')
  getRouters(@Body() body) {
    return this.menuService.getMenus(body);
  }

  @Post('getMenusChildren')
  getRoutersChildren(@Body() body, @Req() req) {
    return this.menuService.getMenusChildren(body, req.roles);
  }

  @Post('create')
  @Roles(['admin', 'manage'])
  createRoute(@Body() body: AdminMenu) {
    return this.menuService.createMenu(body);
  }

  @Delete('delete/:id')
  @Roles(['admin', 'manage'])
  delMenu(@Param() param) {
    return this.menuService.deleteMenu(param.id);
  }

  @Post('update')
  @Roles(['admin', 'manage'])
  updateMenu(@Body() body: AdminMenu) {
    return this.menuService.updateMenu(body);
  }
}
